import md5Libs from "uview-ui/libs/function/md5";
import {SECRETKEY} from "../../config/index"

console.log("-> SECRETKEY", SECRETKEY);
const md5 = md5Libs.md5;
const modal = weex.requireModule("modal");
const globalData = getApp().globalData
export default {
  data() {
    return {
      baseUrl: uni.getStorageSync('baseUrl'),
      isPlay: false,
      isGoodsListShow: false, //商品列表pop显示条件
      isSettingShow: false, // 设置pop显示条件
      isToolShow: false, //  工具 pop显示条件
      isFooterShow: false, //底部footer显示条件
      isLoading: false,
      videoFPS: "",
      videoGOP: "",
      netJitter: "",
      audioBitrate: "",
      netSpeed: "",
      videoBitrate: "",
      system: plus.os.name,
      userInfo: {},
      isShowMessage:false
    }
  },
  mounted() {
    this.isShowMessage = false
     this.userInfo = JSON.parse(uni.getStorageSync("userInfo"));
    console.log("-> this.i18nthis.i18nthis.i18nthis.i18nthis.i18n===", this.i18n);
  },
  computed:{
      getisShowMessage(){
        return !this.isShowMessage || !this.isPlay
      },

  },
  watch:{
    // 原生子窗体遮盖了其它popup，导致无法使用   popup弹出是  hide()   关闭时 show()
    getisShowMessage:{
      handler(val){

        const subNVue = uni.getSubNVueById("anchorSub")
        if(val){
          subNVue.hide()
        }else{
          subNVue.show()
        }
      },
      immediate: true
    }
  },
  methods: {

    // /**
    //  * @description:
    //  * @Author: parker
    //  * @param :  path:api接口路径
    //  * @param :  params: 参数集合对象
    //  * @return {*} method：请求方式
    //  */
    http(path = "", params = {}, method = "POST") {
      const token = uni.getStorageSync("token");
      return new Promise((resolve, reject) => {
        uni.request({
          url: `${this.baseUrl}/${path}?t=${new Date().getTime()}`,
          method: method,
          data: {
            api_token: md5(
              `${path}${this.formartDate()}${SECRETKEY}`
            ),
            client_id: 1,
            token,
            ...params,
          },
          success: (res) => {
            resolve(res);
          },
          fail: (err) => {
            reject(err);
          },
        });
      });
    },
    formartDate() {
      const date = new Date();
      const year = date.getFullYear();
      const month =
        parseInt(date.getMonth()) + 1 > 9
          ? parseInt(date.getMonth()) + 1
          : "0" + (parseInt(date.getMonth()) + 1);
      const day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
      return year + "-" + month + "-" + day;
    },
    inDevelop(){
      return  modal.toast({message:this.i18n('正在内测中，尚未开放，敬请期待')})
    },
  },
};
